Skip to content

Add ADK model handler#37917

Open
damccorm wants to merge 13 commits intomasterfrom
users/damccorm/adkHandler
Open

Add ADK model handler#37917
damccorm wants to merge 13 commits intomasterfrom
users/damccorm/adkHandler

Conversation

@damccorm
Copy link
Copy Markdown
Contributor

Adds model handler capable of running ADK agents mid-pipeline.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new ModelHandler for Apache Beam's ML Inference library, specifically designed to integrate with the Google Agent Development Kit (ADK). This integration allows users to embed sophisticated AI agents, such as large language model agents, directly into their Beam data processing pipelines. The handler manages agent lifecycle and conversation sessions, providing flexibility for various interaction patterns.

Highlights

  • New ADKAgentModelHandler: Introduced ADKAgentModelHandler to enable running Google Agent Development Kit (ADK) agents within Beam pipelines using the RunInference transform.
  • Flexible Agent Instantiation: Implemented support for providing ADK agents either as direct instances or as zero-argument factory callables, accommodating unpicklable agent states.
  • Session Management: Designed session management within the handler to support both stateless (unique session per element) and stateful (shared session_id for multi-turn conversations) agent interactions.
  • Comprehensive Unit Tests: Included comprehensive unit tests for ADKAgentModelHandler covering initialization, model loading, inference execution, and session handling.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 0% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.75%. Comparing base (0afbdf6) to head (633e08a).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
.../apache_beam/ml/inference/agent_development_kit.py 0.00% 68 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             master   #37917    +/-   ##
==========================================
  Coverage     54.75%   54.75%            
  Complexity     1690     1690            
==========================================
  Files          1063     1064     +1     
  Lines        166898   167111   +213     
  Branches       1226     1226            
==========================================
+ Hits          91377    91505   +128     
- Misses        73328    73413    +85     
  Partials       2193     2193            
Flag Coverage Δ
python 80.02% <0.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@damccorm damccorm marked this pull request as ready for review March 24, 2026 15:15
@damccorm damccorm changed the title [WIP] Add ADK model handler Add ADK model handler Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@damccorm
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ADKAgentModelHandler to enable running Google Agent Development Kit (ADK) agents within Apache Beam's RunInference transform. This includes a new Python module for the handler, comprehensive unit tests, and updates to setup.py to include the google-adk dependency. Feedback suggests improving performance by using asyncio.gather for concurrent agent invocations instead of repeated asyncio.run calls, and addressing an import consistency issue in the test file.

@damccorm
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ADKAgentModelHandler to enable running Google Agent Development Kit (ADK) agents within Apache Beam's RunInference transform. This includes the core implementation, a dedicated test file, and updates to dependencies and the CHANGES.md file. Feedback indicates a critical bug where model.session_service.create_session will raise a SessionExistsError for elements beyond the first when a shared session_id is used, requiring a try...except block. Additionally, the response extraction in _invoke_agent should be improved to handle multi-part agent responses completely by using event.content.text instead of event.content.parts[0].text.

damccorm and others added 2 commits March 26, 2026 09:05
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@damccorm
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ADKAgentModelHandler to integrate Google Agent Development Kit (ADK) agents with Apache Beam's RunInference transform, allowing users to run ADK agents within Beam pipelines. This involves adding a new Python module, corresponding unit tests, updating the CHANGES.md file, and adding google-adk as a dependency in setup.py. A review comment highlighted a bug where SessionExistsError is used in the new handler without being imported, which could lead to a NameError.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@damccorm
Copy link
Copy Markdown
Contributor Author

/gemini review

@damccorm damccorm marked this pull request as draft March 26, 2026 13:36
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces ADKAgentModelHandler for running Google Agent Development Kit (ADK) agents within Apache Beam's RunInference transform, along with corresponding unit tests. It also adds google-adk as a dependency. A critical issue was identified where the sessions module was used without being imported, which would lead to a NameError at runtime.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Ganeshsivakumar
Copy link
Copy Markdown
Contributor

Really exciting PR. This could be like Flink Agents of Beam.

@damccorm
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ADKAgentModelHandler to the Apache Beam Python SDK, enabling the integration of Google Agent Development Kit (ADK) agents with the RunInference transform. The implementation includes support for session management to facilitate stateful multi-turn conversations and utilizes asyncio for concurrent agent invocations. A review comment suggests a refactoring of the run_inference method to eliminate a redundant list and use a list comprehension, which would improve the code's conciseness and readability.

@damccorm damccorm marked this pull request as ready for review March 27, 2026 18:04
@damccorm
Copy link
Copy Markdown
Contributor Author

assign set of reviewers

@github-actions
Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants